package com.xiaomengkuan.user.controller;

import com.xiaomengkuan.common.util.DetailSelector;
import com.xiaomengkuan.common.util.R;
import com.xiaomengkuan.user.entity.vo.UserResponseVo;
import com.xiaomengkuan.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Faraj Mujey
 * -- Creation Time: 2021-01-29 3:51 下午, File Encoding: utf8 --
 */
@RestController
@RequestMapping("user/info")
@Api(tags = "用户信息管理")
public class InfoController {

    @Resource
    private UserService userService;

    /**
     * 修改用户信息
     * @param requestBody 用户信息
     * @return R
     */
    @ApiOperation(value = "修改用户信息")
    @PostMapping("modify")
    public R modifyInfo(@RequestBody Map<String, Object> requestBody){
        boolean flag = userService.modifyInfo(requestBody);
        return flag ? R.ok().detail(DetailSelector.UPDATE_SUCCESS) :
                R.err().detail(DetailSelector.UPDATE_ERROR);
    }

    /**
     * 获取用户信息
     * @param id 用户id
     * @return R
     */
    @ApiOperation(value = "获取用户信息")
    @GetMapping("get/{id}")
    public R get(@PathVariable("id") String id){
        UserResponseVo vo = userService.getInfo(id);
        return R.ok().detail(DetailSelector.QUERY_SUCCESS).putItem(vo);
    }
}
